package com.triptogether.utils.facebook;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.facebook.UiLifecycleHelper;
import com.triptogether.R;
import com.triptogether.baseclasses.BaseFragment;
import com.triptogether.utils.log.Logger;

public class LoginFacebookFragment extends BaseFragment {

	private final String TAG = Logger.makeLogTag(this.getClass());
	private UiLifecycleHelper uiHelper;
	LoginFacebookListener listenerActvity;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
	        Bundle savedInstanceState) {
		return inflater.inflate(R.layout.fragment_login_facebook, container, false);
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		try {
			listenerActvity = (LoginFacebookListener) getActivity();
		} catch (ClassCastException e) {
			Logger.LOGE(TAG,
			            String.format("The activity %s uses %s and not implements %s",
			                          getActivity().getClass().getName(),
			                          LoginFacebookFragment.class.getName(),
			                          LoginFacebookListener.class.getName()));
		}
		uiHelper = new UiLifecycleHelper(getActivity(),
		        listenerActvity.getStatusCallback());
		uiHelper.onCreate(savedInstanceState);
	}
	
	@Override
	public void onResume() {
		super.onResume();
		
		uiHelper.onResume();	
	}

	@Override
	public void onPause() {
		super.onPause();
		uiHelper.onPause();
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
		uiHelper.onDestroy();
	}

	@Override
	public void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		uiHelper.onSaveInstanceState(outState);
	}
}
